home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 December / 2004-12 CHIP.iso / Narzedzia systemowe / Inno Setup 5.0.4 Beta / isetup-5.0.4-beta.exe / {app} / Examples / CodeExample1.iss < prev    next >
Text File  |  2004-08-02  |  5KB  |  125 lines

  1. ; -- CodeExample1.iss --
  2. ;
  3. ; This script shows various things you can achieve using a [Code] section
  4.  
  5. [Setup]
  6. AppName=My Program
  7. AppVerName=My Program version 1.5
  8. DefaultDirName={code:MyConst}\My Program
  9. DefaultGroupName=My Program
  10. UninstallDisplayIcon={app}\MyProg.exe
  11. InfoBeforeFile=Readme.txt
  12.  
  13. [Files]
  14. Source: "MyProg.exe"; DestDir: "{app}"; Check: MyProgCheck; BeforeInstall: BeforeMyProgInstall('MyProg.exe'); AfterInstall: AfterMyProgInstall('MyProg.exe')
  15. Source: "MyProg.hlp"; DestDir: "{app}"; Check: MyProgCheck; BeforeInstall: BeforeMyProgInstall('MyProg.hlp'); AfterInstall: AfterMyProgInstall('MyProg.hlp')
  16. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
  17.  
  18. [Icons]
  19. Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
  20.  
  21. [Code]
  22. var
  23.   MyProgChecked: Boolean;
  24.   MyProgCheckResult: Boolean;
  25.   FinishedInstall: Boolean;
  26.  
  27. function InitializeSetup(): Boolean;
  28. begin
  29.   Result := MsgBox('InitializeSetup:' #13#13 'Setup is initializing. Do you really want to start setup?', mbConfirmation, MB_YESNO) = idYes;
  30.   if Result = False then
  31.     MsgBox('InitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
  32. end;
  33.  
  34. procedure DeinitializeSetup();
  35. var
  36.   FileName: String;
  37.   ResultCode: Integer;
  38. begin
  39.   if FinishedInstall then begin
  40.     if MsgBox('DeinitializeSetup:' #13#13 'The [Code] scripting demo has finished. Do you want to uninstall My Program now?', mbConfirmation, MB_YESNO) = idYes then begin
  41.       FileName := ExpandConstant('{uninstallexe}');
  42.       if not Exec(FileName, '', '', SW_SHOWNORMAL, ewNoWait, ResultCode) then
  43.         MsgBox('DeinitializeSetup:' #13#13 'Execution of ''' + FileName + ''' failed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
  44.     end else
  45.       MsgBox('DeinitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
  46.   end;
  47. end;
  48.  
  49. procedure CurStepChanged(CurStep: TSetupStep);
  50. begin
  51.   if CurStep = ssPostInstall then
  52.     FinishedInstall := True;
  53. end;
  54.  
  55. function NextButtonClick(CurPageID: Integer): Boolean;
  56. var
  57.   ResultCode: Integer;
  58. begin
  59.   case CurPageID of
  60.     wpSelectDir:
  61.       MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardDirValue + '''.', mbInformation, MB_OK);
  62.     wpSelectProgramGroup:
  63.       MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardGroupValue + '''.', mbInformation, MB_OK);
  64.     wpReady:
  65.       begin
  66.         if MsgBox('NextButtonClick:' #13#13 'Using the script, files can now be extracted before the installation starts. For example we could extract ''MyProg.exe'' now and run it.' #13#13 'Do you want to do this?', mbConfirmation, MB_YESNO) = idYes then begin
  67.           if ExtractTemporaryFile('myprog.exe') then begin
  68.             if not Exec(ExpandConstant('{tmp}\myprog.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then
  69.               MsgBox('NextButtonClick:' #13#13 'The file could not be executed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
  70.           end else
  71.             MsgBox('NextButtonClick:' #13#13 'The file could not be extracted.', mbError, MB_OK);
  72.         end;
  73.         BringToFrontAndRestore();
  74.         MsgBox('NextButtonClick:' #13#13 'The normal installation will now start.', mbInformation, MB_OK);
  75.       end;
  76.   end;
  77.  
  78.   Result := True;
  79. end;
  80.  
  81. function ShouldSkipPage(PageID: Integer): Boolean;
  82. begin
  83.   { Skip wpInfoBefore page; show all others }
  84.   case PageID of
  85.     wpInfoBefore:
  86.       Result := True;
  87.   else
  88.     Result := False;
  89.   end;
  90. end;
  91.  
  92. procedure CurPageChanged(CurPageID: Integer);
  93. begin
  94.   case CurPageID of
  95.     wpWelcome:
  96.       MsgBox('CurPageChanged:' #13#13 'Welcome to the [Code] scripting demo. This demo will show you some possibilities of the scripting support.' #13#13 'The scripting engine used is RemObjects Pascal Script by Carlo Kok. See http://www.remobjects.com/?ps for more information.', mbInformation, MB_OK);
  97.     wpFinished:
  98.       MsgBox('CurPageChanged:' #13#13 'Welcome to final page of this demo. Click Finish to exit.', mbInformation, MB_OK);
  99.   end;
  100. end;
  101.  
  102. function MyProgCheck(): Boolean;
  103. begin
  104.   if not MyProgChecked then begin
  105.     MyProgCheckResult := MsgBox('MyProg:' #13#13 'Do you want to install MyProg.exe and MyProg.hlp to ' + ExtractFilePath(CurrentFileName) + '?', mbConfirmation, MB_YESNO) = idYes;
  106.     MyProgChecked := True;
  107.   end;
  108.   Result := MyProgCheckResult;
  109. end;
  110.  
  111. procedure BeforeMyProgInstall(S: String);
  112. begin
  113.   MsgBox('BeforeMyProgInstall:' #13#13 'Setup is now going to install ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
  114. end;
  115.  
  116. procedure AfterMyProgInstall(S: String);
  117. begin
  118.   MsgBox('AfterMyProgInstall:' #13#13 'Setup just installed ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
  119. end;
  120.  
  121. function MyConst(Param: String): String;
  122. begin
  123.   Result := ExpandConstant('{pf}');
  124. end;
  125.